package kr.co.boogui.dao;

import java.util.List;

import mybatis3.helper.MVCSqlSessionFactory;

import org.apache.ibatis.session.SqlSession;

import kr.co.boogui.model.ComParamVO;

import kr.co.boogui.model.InfoCommentVO;

public class InfoCommentDAO {

	private static int perpage = 20;

	public static List<InfoCommentVO> listBoard(int startno, String movno) {

		List<InfoCommentVO> result = null;
		kr.co.boogui.model.ComParamVO pvo = new ComParamVO();
		pvo.setStartno(startno);
		pvo.setPerpage(perpage);
		pvo.setMovno(movno);

		SqlSession sess = MVCSqlSessionFactory.openSession();

		try {
			result = sess.selectList("CommentMapper.findlistSQL", pvo);

		} finally {
			sess.close();

		}
		return result;
	}

	public static int totalBoard() {

		int result = -1;
		SqlSession sess = MVCSqlSessionFactory.openSession();
		try {
			result = sess.selectOne("CommentMapper.totalSQL");
		} finally {
			sess.close();
		}
		return result;

	}

	public static boolean writeBoard(InfoCommentVO b) {
		boolean result = false;
		SqlSession sess = null;		
		try {
			sess = MVCSqlSessionFactory.openSession();
			if (sess.insert("CommentMapper.insertSQL", b) > 0)
				result = true;
			sess.commit(); // insert 및 update 시 반드시 작성 !!
             
		} finally {
			sess.close();

		}
		return result;
	}

	

	

	

	public static InfoCommentVO viewBoard(String movno) {
		InfoCommentVO result = null;
		SqlSession sess = null;

		try {
			sess = MVCSqlSessionFactory.openSession();
			result = sess.selectOne("CommentMapper.viewSQL",movno);
			
		} finally {
			sess.close();
		}
		return result;
	}

	public static void viewCountBoard(String movno) {
		SqlSession sess = null;
		try {
			sess = MVCSqlSessionFactory.openSession();
			sess.update("CommentMapper.viewcountSQL", movno);
			sess.commit();
		} finally {
			sess.close();
		}

	}

}
